﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;


namespace GDCommon.Mail
{
    public class MailBLL
    {

        static string reg = @"^(?<USER>(\w+([-+.]\w+)*))@\w+([-.]\w+)*\.\w+([-.]\w+)*$";

        public MailBLL()
        {
            //
            // TODO: Add constructor logic here
            //
        }


        //转发好友
        public static void SendMail(String email)
        {
            string objective = getUser(email);

            SmptMailHelper mail = new SmptMailHelper();
            //mail.Host = ConfigHelper.Host;
            //mail.Port = ConfigHelper.Port;
            //mail.Sender = ConfigHelper.Sender;
            mail.SenderName = "aaaaa";
            mail.Reciever = email;
            mail.Subject = "111";
            mail.Body = "22222222";
            mail.Send();
        }

        //获得邮件地址的前缀
        public static string getUser(string email)
        {

            System.Text.RegularExpressions.Regex rxx = new System.Text.RegularExpressions.Regex(reg,
                        RegexOptions.Compiled | RegexOptions.IgnoreCase);

            MatchEvaluator myEvaluator = new MatchEvaluator(USERMatch);

            string objective = rxx.Replace(email, myEvaluator);

            return objective;
        }

        static string USERMatch(Match m)
        {
            if (m.Groups["USER"].ToString() != "")
            {
                return m.Groups["USER"].ToString();
            }
            else
            {
                return m.Groups[0].ToString();
            }
        }
    }
}
